package com.d404.im;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import com.alibaba.fastjson.JSON;

import guanqu.beans.HistoryIrrBRWaterDam;
import guanqu.beans.RealTimeIrrBRWaterDam;
import manager.Utils;

/**
 * Servlet implementation class Test
 */
@WebServlet("/Test")
public class Test extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Test() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	
	
	@org.junit.Test
	public void test1()
	{
		ArrayList a = new ArrayList();
		a.add(34);
		a.add(43);
		a.add("leikai'");
		System.out.println(JSON.toJSONString(a));
		System.out.println(JSON.toJSONString(new String[]{"leikai","haha"}));
	}
	
	@org.junit.Test
	public void test2()
	{
		System.out.println(Utils.timestamp2Format(1447317526473L));
	}
	
	@org.junit.Test
	public void test3()
	{
		RealTimeIrrBRWaterDam realTimeIrrBRWaterDam = new RealTimeIrrBRWaterDam();
		realTimeIrrBRWaterDam.setFluxGate(new BigDecimal("34.324"));
		
		HistoryIrrBRWaterDam historyIrrBRWaterDam = new HistoryIrrBRWaterDam();
		try {
			BeanUtils.copyProperties(historyIrrBRWaterDam, realTimeIrrBRWaterDam);
			System.out.println("..");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@org.junit.Test
	public void test4()
	{
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		System.out.println(simpleDateFormat.format(Calendar.getInstance().getTime()));
	}
	
	
	@org.junit.Test
	public void test5()
	{
//		HashMap map = new HashMap<>();
//		map.put("0", "243.23");
//		map.put("1", "");
//		System.out.println(JSON.toJSONString(map));
//		
//		HashMap map2 = JSON.parseObject(JSON.toJSONString(map),HashMap.class);
		
		
		ArrayList<Part> parts = new ArrayList<>();
		parts.add(new Part(0, new BigDecimal("3432.342")));
		parts.add(new Part(1, new BigDecimal("3432.342")));
		
		System.out.println(JSON.toJSONString(parts));
		
		ArrayList<Part> parts2 = (ArrayList<Part>) JSON.parseArray(JSON.toJSONString(parts), Part.class);
		System.out.println("..");
		
	}
	
	// 每个闸门的命令
	public static class Part
	{
		// 闸门编号 1-5
		int n;
		// 上升，下降尺度
		BigDecimal b;
		
		public Part(){}
		
		public Part(int n, BigDecimal b) {
			super();
			this.n = n;
			this.b = b;
		}
		public int getN() {
			return n;
		}
		public void setN(int n) {
			this.n = n;
		}
		public BigDecimal getB() {
			return b;
		}
		public void setB(BigDecimal b) {
			this.b = b;
		}
		
		
	}

}
